﻿using System;

namespace Chambills.Present.Core
{
    /// <summary>
    /// A class to simplify scoped actions
    /// <example> 
    /// using(mocks.Unordered())
    ///  {
    ///          // Do Something
    ///  }
    /// </example>
    /// </summary>
    public class DisposableAction : ManagedDisposable
    {
        readonly Action action;

        public DisposableAction(Action action)
        {
            if (action == null)
                throw new ArgumentNullException("action");
            this.action = action;
        }

        protected override void DisposeResources()
        {
            base.DisposeResources();
            action();
        }
    }
}